#pragma once
#include <string>
#include <memory>
#include <vector>

using namespace std;
using namespace std::tr1;

class CTabView
{
private:
	const wstring m_title;
	const wstring m_id;
	int m_nIndex;

protected:
	HWND m_hWnd;
	virtual HWND Create(HWND hParent, HINSTANCE hInstance) = 0;

public:
	CTabView(const wstring &title, const wstring &id) : m_title(title), m_id(id) {}
	virtual ~CTabView();
	HWND CreateTab(HWND hParent, HINSTANCE hInstance, int index) { m_hWnd = Create(hParent, hInstance); m_nIndex = index; return m_hWnd; }
	const wstring &GetTitle() const { return m_title; }
	const wstring &GetId() const { return m_id; }
	const int &GetIndex() const { return m_nIndex; }
	virtual void Show();
	virtual void Hide();
	virtual void SetSize(RECT rect);
	
}; 



class CTabContainer
{
	friend LRESULT SubClassForRichEdit(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
	friend LRESULT SubClassForTabControl(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);

	
private:

	static CTabContainer *s_pTheTabContainer;

	HWND m_hWnd;
	HINSTANCE m_hInstance;
	vector<shared_ptr<CTabView>> m_tabs;
	unsigned int m_nextItem;
	shared_ptr<CTabView> m_currentSelectedTab;
	RECT m_tabRect;
	bool CheckTabId(shared_ptr<CTabView> tab, const wstring &id) const;
	RECT CTabContainer::GetTabSize() const;
	void  SetTabSize(shared_ptr<CTabView> tabView);
	void  UpdateTabSizes();
	LRESULT ProcessMessageForSwitchTab(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam, WNDPROC lpfnOldWndProc);

public:
	CTabContainer(HWND hParent, HINSTANCE hInstance, RECT tabRect);
	void UpdateTabSize(RECT r);
	void AddTab(shared_ptr<CTabView> tabView);
	void DeleteTab(shared_ptr<CTabView> tabView);
	shared_ptr<CTabView> GetTabById(const wstring &id);
	~CTabContainer(void);
	void TabChanged();
	void SwitchToTab(shared_ptr<CTabView> tabView);
	void Copy();


};
